package cz.cvut.felk.via.sm.rest.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cv.cvut.felk.via.sm.services.SubjectDummyService;
import cz.cvut.felk.via.sm.exceptions.ResourceNotFoundException;
import cz.cvut.felk.via.sm.model.Subject;

@Controller
public class SubjectJsonController {
	SubjectDummyService subjectDummyService;

	
	
	public SubjectDummyService getSubjectDummyService() {
		return subjectDummyService;
	}
	public void setSubjectDummyService(SubjectDummyService subjectDummyService) {
		this.subjectDummyService = subjectDummyService;
	}
	@RequestMapping(value="/subject/{user}", method=RequestMethod.GET)
	@ResponseBody
	@SuppressWarnings("unchecked")
	public List<Subject> getusersSubject(@PathVariable String user)throws ResourceNotFoundException{
		List<Subject> subjects = subjectDummyService.getUsersSubject(user);
		if(subjects==null){
			
			throw new ResourceNotFoundException(user);
		}
		return subjects;
	}
	@RequestMapping(value="/subject",method=RequestMethod.GET)
	public ModelAndView getSubjects(){
		Map<String,Object> model = new HashMap<String, Object>();
		List<Subject> subjects = subjectDummyService.getUsersSubject("student");
		model.put("subjects", subjects);
		return(new ModelAndView("subjects",model));
	}
	
}
